package com.exam.online.system.controller;

import com.exam.online.system.constant.StatusCode;
import com.exam.online.system.entity.Course;
import com.exam.online.system.entity.Question;
import com.exam.online.system.model.ConditionQuestionModel;
import com.exam.online.system.service.ConditionService;
import com.exam.online.system.service.QuestionService;
import com.exam.online.system.util.ResponseModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

import static com.exam.online.system.constant.Constant.SERVICE_PATH_PUBLIC;

/**
 * @author yuzhen
 * @date 2019/5/6
 */
@RestController
@RequestMapping(SERVICE_PATH_PUBLIC)
public class ConditionController {

    @Autowired
    private ConditionService conditionService;
    @Autowired
    private QuestionService questionService;

    //{{url}}/public/online/exam/

    /**
     * 通过教师获取年级列表和课程列表
     */
    @PostMapping("/condition/findConditionsByTeacherId")
    public ResponseModel findConditionsByTeacherId(@RequestParam("teacherId") Integer teacherId) {
        List<ConditionQuestionModel> conditionsByTeacherId = conditionService.findConditionsByTeacherId(teacherId);
        return ResponseModel.buildFromStateCode(StatusCode.SUCCESS, conditionsByTeacherId);
    }

    /**
     * 通过年级，课程，题目类型查找题目列表
     */
    @PostMapping("/condition/findQuestionByCondition")
    public ResponseModel findQuestionByCondition(@RequestParam("courseName") String courseName,
                                                 @RequestParam("gradeId") Integer gradeId) {
        return questionService.findQuestionByCondition(courseName, gradeId);
    }

    /**
     * 通过教师查询课程列表
     *
     * @return
     */
    @PostMapping("/condition/findCourse")
    public ResponseModel findCourse(@RequestParam("teacherId") Integer teacherId) {
        List<Course> courseByTeacherId = conditionService.findCourseByTeacherId(teacherId);
        return ResponseModel.buildFromStateCode(StatusCode.SUCCESS, courseByTeacherId);
    }

    /**
     * 根据年级获取课程
     */
    @PostMapping("/condition/findCourseByGrade")
    public ResponseModel findCourseByGrade(@RequestParam("gradeId") Integer gradeId) {
        return ResponseModel.buildFromStateCode(StatusCode.SUCCESS, conditionService.findCourseByGrade(gradeId));
    }
}
